package com.openess.bigsearch.engine.utils;

import java.util.Iterator;

/**
 * 以链表实现的栈
 * 
 * @author TuTu
 * 
 * @param <E>
 *            插入的元素类型
 */
public class LinkedStack<E> implements SStack<E> {
	/**
	 * 栈只能在一端进行插入/取出操作，即在top端进行操作，也是头指针
	 */
	private Node<E> top;

	public LinkedStack() {
		this.top = null;
	}

	public LinkedStack(E element) {
		this.top = null;
		push(element);
	}

	@Override
	public Iterator<E> iterator() {
		return null;
	}

	@Override
	public boolean contain(E elements) {
		return false;
	}

	@Override
	public boolean isEmpty() {
		return this.top == null;
	}

	@Override
	public <T> T[] toArray(T[] a) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T[] toArray(T a) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object toArray() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean push(E element) {
		if (element == null) {
			return false;
		}
		this.top = new Node<E>(element, top);
		return true;
	}

	@Override
	public E pop() {
		if (isEmpty()) {
			return null;
		}
		E result = top.getData();
		top = top.getNext();
		return result;
	}

	@Override
	public E get() {
		if (isEmpty()) {
			return null;
		}
		E result = top.getData();
		return result;
	}

}
